#include <stdio.h>
#include <string.h>
char *strsep(char **stringp, const char *delim){
	const char *spanp;
	char *s, *tok;
	int c, sc;
	if((s = *stringp)== NULL) return NULL;
	for(tok = s;;){
		c = *s++, spanp = delim;
		do{
			if((sc =*spanp++) == c){
				if(c == 0) s = NULL;
				else s[-1] = 0;
				*stringp = s;
				return (tok);
			}
		}while(sc != 0);
	}
}
int main(){
	int len;
	char query[] = "a=1&b=2&c=3";
	char *q, *name, *value, *t;
	/* fprintf(stdout, "CGI[query string]: %s\n\n", query); */
	len = strlen(query);

	name = value = query;
	while(strsep(&value, "&")){
		printf("%s, %s\n", name, value);
		name = value;
	}

	printf("\n");
	for(q=query,t=query+len; q<t;){
		value = name = q;
		/* q += strlen(q) + 1; */
		for(q+=strlen(q); q<(query+len)&&!*q; q++);

		strsep(&value, "=");
		fprintf(stdout, "CGI: %s = %s\n\n", name, value);
	}
	return 0;
}
